package Interface.Hoteleria;

import Interface.Acceso;
import Interface.GUIM;
import LN.Alquileres.Tarifa_Salon;
import LN.Varios.Hosteria;
import javax.swing.SwingUtilities;

public class Parametros_Salon extends javax.swing.JPanel {

    Hosteria unaHosteria;

    public Parametros_Salon(Hosteria unHosteria) {
        this.unaHosteria = unHosteria;
        initComponents();
        if (unHosteria.getSalon().isEstado_limpieza()) {
            radio_limpia.setSelected(true);
        } else {
            radio_sucia.setSelected(true);
        }

        if (unHosteria.getSalon().isHabilitado()) {
            radio_habilitado.setSelected(true);
        } else {
            radio_deshabilitado.setSelected(true);
        }


        for (Tarifa_Salon unaTarifa_Salon : unaHosteria.getTarifas_Salon()) {
            switch (unaTarifa_Salon.getTipo()) {
                case Tarifa_Salon.S:
                    txt_S.setText(String.valueOf(unaTarifa_Salon.getPrecio()));
                case Tarifa_Salon.SL:
                    txt_SL.setText(String.valueOf(unaTarifa_Salon.getPrecio()));
                case Tarifa_Salon.SLS:
                    txt_SLS.setText(String.valueOf(unaTarifa_Salon.getPrecio()));

            }
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        radio_sucia = new javax.swing.JRadioButton();
        radio_deshabilitado = new javax.swing.JRadioButton();
        radio_limpia = new javax.swing.JRadioButton();
        radio_habilitado = new javax.swing.JRadioButton();
        btn_Aceptar = new javax.swing.JButton();
        btn_Cancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txt_SL = new javax.swing.JTextField();
        txt_SLS = new javax.swing.JTextField();
        txt_S = new javax.swing.JTextField();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jTextField1.setEditable(false);
        jTextField1.setBackground(new java.awt.Color(153, 153, 153));
        jTextField1.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 18)); // NOI18N
        jTextField1.setForeground(new java.awt.Color(255, 255, 255));
        jTextField1.setText("Parámetros del Salón");
        jTextField1.setFocusable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Opciones de Estado"));

        radio_sucia.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_sucia.setText("Sucio");

        radio_deshabilitado.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_deshabilitado.setText("No Habilitado");

        radio_limpia.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_limpia.setText("Limpio");

        radio_habilitado.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_habilitado.setText("Habilitado");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radio_habilitado)
                    .addComponent(radio_deshabilitado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radio_limpia)
                    .addComponent(radio_sucia))
                .addGap(35, 35, 35))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radio_habilitado)
                    .addComponent(radio_limpia))
                .addGap(12, 12, 12)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radio_deshabilitado)
                    .addComponent(radio_sucia)))
        );

        btn_Aceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Guardar_2.png"))); // NOI18N
        btn_Aceptar.setText("Aceptar");
        btn_Aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AceptarActionPerformed(evt);
            }
        });

        btn_Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Close.png"))); // NOI18N
        btn_Cancelar.setText("Cancelar");
        btn_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CancelarActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tarifas del Salón"));

        jLabel2.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel2.setText("Salon + Limpieza");

        jLabel3.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel3.setText("Salon + Limpieza + Sonido");

        jLabel4.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel4.setText("Salon:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_SLS, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_S, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_SL, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txt_S, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txt_SL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txt_SLS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTextField1)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btn_Aceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btn_Cancelar)
                .addContainerGap())
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_Aceptar)
                    .addComponent(btn_Cancelar))
                .addContainerGap())
        );

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

    private void btn_AceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AceptarActionPerformed

        boolean limpia = false;
        boolean habilitada = false;

        if (radio_deshabilitado.isSelected()) {
            habilitada = false;
        } else if (radio_habilitado.isSelected()) {
            habilitada = true;
        }

        if (radio_limpia.isSelected()) {
            limpia = true;
        } else if (radio_sucia.isSelected()) {
            limpia = false;
        }

        double precios[] = new double[3];
        double tarifasAnteriores[] = new double[3];

        precios[0] = Double.valueOf(txt_S.getText());
        precios[1] = Double.valueOf(txt_SL.getText());
        precios[2] = Double.valueOf(txt_SLS.getText());

        for (Tarifa_Salon unaTarifa : unaHosteria.getTarifas_Salon()) {
            switch (unaTarifa.getTipo()) {
                case "Salon":
                    tarifasAnteriores[0] = unaTarifa.getPrecio();
                case "Salon + Limpieza":
                    tarifasAnteriores[1] = unaTarifa.getPrecio();
                case "Salon + Limpieza + Sonido":
                    tarifasAnteriores[2] = unaTarifa.getPrecio();

            }
        }

        if (precios[0] != tarifasAnteriores[0]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa del Salon (Salon) de " + String.valueOf(tarifasAnteriores[0]) + " a " + txt_S.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }
        if (precios[1] != tarifasAnteriores[1]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa del Salon (Salon + Limpieza) de " + String.valueOf(tarifasAnteriores[1]) + " a " + txt_SL.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }
        if (precios[2] != tarifasAnteriores[2]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa del Salon (Salon + Limpieza + Sonido) de " + String.valueOf(tarifasAnteriores[2]) + " a " + txt_SLS.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }


        unaHosteria.cambiarEstado_Salon(unaHosteria.getSalon(), habilitada, limpia, precios);
//        unaHosteria.crearAuditoria("MOD", "Modificó un estado (Habitacion " + unaHabitacion.getNumero() + ")", Acceso.getUsuario(), GUIM.getHoraActual());
        //        SwingUtilities.getWindowAncestor(this).dispose();
    }//GEN-LAST:event_btn_AceptarActionPerformed

    private void btn_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CancelarActionPerformed
        SwingUtilities.getWindowAncestor(this).dispose();
    }//GEN-LAST:event_btn_CancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Aceptar;
    private javax.swing.JButton btn_Cancelar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JRadioButton radio_deshabilitado;
    private javax.swing.JRadioButton radio_habilitado;
    private javax.swing.JRadioButton radio_limpia;
    private javax.swing.JRadioButton radio_sucia;
    private javax.swing.JTextField txt_S;
    private javax.swing.JTextField txt_SL;
    private javax.swing.JTextField txt_SLS;
    // End of variables declaration//GEN-END:variables
}
